package com.kjj.gift.exception.asserts;

import com.kjj.gift.exception.BusinessException;
import com.kjj.gift.exception.code.StatusCode;

import java.util.List;

public class Assert {
    /**
     * 断言List是空
     * @param list
     * @param code 状态码
     */
    public static void assertListIsEmpty(List<?> list, StatusCode code){
        if (list!=null && list.size()>0)
            throw new BusinessException(code.getCode(),code.getMessage());
    }
    /**
     * 断言不为null,如果为null就抛出异常
     * @param obj
     * @param message
     */
    public static void assertNotNull(Object obj,String message){
        if (obj==null)
            throw new BusinessException(message);
    }

    /**
     * 断言不为空串
     * @param str
     * @param message
     */
    public static void assertNotEmpty(String str,String message){
        if (str==null || str.trim().equals(""))
            throw new BusinessException(StatusCode.CODE_403_FORBIDDEN.getCode(), message);
    }
    /**
     * 断言不为空串
     * @param str
     * @param code
     */
    public static void assertNotEmpty(String str,StatusCode code){
        if (str==null || str.trim().equals(""))
            throw new BusinessException(code.getCode(),code.getMessage());
    }
    /**
     * 断言不为空串
     * @param str
     * @param message
     */
    public static void assertIsEmpty(String str,String message){
        if (str!=null)
            throw new BusinessException(StatusCode.CODE_500.getCode(),message);
    }
    /**
     * 断言不为空串
     * @param str
     * @param code
     */
    public static void assertIsEmpty(String str,StatusCode code){
        if (str!=null)
            throw new BusinessException(code.getCode(),code.getMessage());
    }

    /**
     * 断言List是空
     * @param list
     * @param message
     */
    public static void assertListIsEmpty(List<?> list, String message){
        if (list!=null && list.size()>0)
            throw new BusinessException(message);
    }



    /**
     * 断言List不为null
     * @param list
     * @param message
     */
    public static void assertListNotEmpty(List<?> list, String message){
        if (list==null || list.size()<1)
            throw new BusinessException(message);
    }

    /**
     * 断言List不为null
     * @param list
     * @param statusCode
     */
    public static void assertListNotEmpty(List<?> list, StatusCode statusCode){
        if (list==null || list.size()<1)
            throw new BusinessException(statusCode.getCode(),statusCode.getMessage());
    }
    /**
     * 断言相等
     * @param str1
     * @param str2
     * @param message
     */
    public static void assertEquals(String str1,String str2,String message){

        if (!str1.trim().equals(str2.trim()))
            throw new BusinessException(message);
    }
    public static void assertEqualsIgnoreCase(String str1,String str2,String message){

        if (!str1.trim().equalsIgnoreCase(str2.trim()))
            throw new BusinessException(message);
    }
    public static void assertEqualsIgnoreCase(String str1,String str2,StatusCode code){

        if (!str1.trim().equalsIgnoreCase(str2.trim()))
            throw new BusinessException(code.getCode(),code.getMessage());
    }
    /**
     * 断言不相等
     * @param str1
     * @param str2
     * @param message
     */
    public static void assertNotEquals(String str1,String str2,String message){

        if (str1.trim().equals(str2.trim()))
            throw new BusinessException(message);
    }
}
